Make OwnedRepr an "aliasable owner" instead of using Vec#799
Merged
Conversation
Avoid the unique ownership meaning of Vec by storing the fields raw in our own representation. Supply conversion to/from Vec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The owned array has used a
Vec<T>that it owns, and kept a separate "head pointer"ptron the side; the head pointer points to the first element in the array, somewhere inside the vector's data.The Vec uses a "unique" owning pointer - not a building block that is available outside std - so just like Box, it should in principle not be possible to modify the vector's data through anything else than its own data pointer. Our head pointer can violate this.
We replace the Vec with a deconstructed vector; it's equivalent but uses
NonNull<T>for its pointer, so it's an aliasable owner.This does not change how owned arrays are allocated, only how it is modelled in the type system. The change affects all the owned arrays (Array, ArcArray, CowArray).
cc #796
In principle, this problem is described in issue Kimundi/owning-ref-rs#49
This soundness concern does not currently seem to yield any problems in practice, because the compiler does not take advantage of the properties of Vec's unique pointer.